﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCF20Module.ZICModel;
using Newtonsoft.Json;
using CCF20Model;
using System.ServiceModel;
using System.Windows;
using System.Diagnostics;
using WiseLink.RDS.Resource;

namespace CCF20Module
{
    
    public class CCFZIC
    {
        private string PID = "1";
        private string Pwd = "123";
        
        private VehicleModel vehicleModel;
        private FaultModel faultModel;
        private DeviceModel deviceModel;
        private VehicleMaintenanceModel maintenanceModel;
        private ModelFactory modelFactory;
        
        public CCFZIC()
        {
            modelFactory = new ModelFactory();
            vehicleModel = (VehicleModel)modelFactory.CreateModel(ModelName.VehicleModel);
            faultModel = (FaultModel)modelFactory.CreateModel(ModelName.FaultModel);
            deviceModel = (DeviceModel)modelFactory.CreateModel(ModelName.DeviceModel);
            PID = ZICMonitorModel.ZICLoginInfo.IDSName;
            Pwd = ZICMonitorModel.ZICLoginInfo.IDSPassword;
            
            if (ZICMonitorModel.IsJava)
            {
                LoggerHelper.LogCCF20(string.Format("Java/Mobile ZIC Url: {0}", ZICMonitorModel.ZICUrl));
            }
            else
            {
                LoggerHelper.LogCCF20(string.Format("NET/FAW ZIC Url: {0}", ZICMonitorModel.ZICUrl));
            }
            
        }

       

        public void GetFHList()
        {
            int anchiID = deviceModel.GetAnchiID();
            string ret;
            if (ZICMonitorModel.IsJava)
            {
                return; //对于移动版本我们没有这个API。
                //ret = string.Empty;//ZICMonitorModel.ZICJava.GetFhList(PID, Pwd, anchiID);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.GetFhList(PID, Pwd, anchiID);
            }
            LoggerHelper.LogCCF20(string.Format("GetFhList IDS={0},AnchiID={1}",PID,anchiID));
            if (ret == null || ret == string.Empty)
            {
                return;
            }
            else
            {
                if (ret.Equals("LoginErr", StringComparison.InvariantCultureIgnoreCase))
                {
                    Utility.ShowMessageBox(Message.ZIC_IDSUserPasswordMismatch);
                    return;
                }
            }
            List<FhList> list = (List<FhList>)JavaScriptConvert.DeserializeObject(ret, typeof(List<FhList>));
            
            foreach (FhList model in list)
            {
                Device device = new Device();
                device.AnchiID = Convert.ToInt32(model.Xsid); //id in the sales list is used for AnchiID
                if (!ZICMonitorModel.IsJava && !model.Idc.StartsWith("86"))
                {
                    //只有星网的ZIS才会加86作为SIM
                    device.IDCSimNumber = "86" + model.Idc;
                }
                else
                {
                    device.IDCSimNumber = model.Idc;
                }
                device.DeviceKey = model.Xlh;
                device.Invoice = model.Ss_paper;
                device.DeviceType = model.Cpxh;
                device.DeviceStatus = DeviceStatus.Shipped;
                device.IsManual = false;
                deviceModel.AddDevice(device);

            }


        }
        public bool UploadCustomerInfo(Device device)
        {
            string ret;
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.UpdMesByUpdClient(
                                            PID,
                                            Pwd,
                                            device.IDCSimNumber,
                                            device.Vehicle.VehicleType.Model,
                                            device.Vehicle.VehicleLicense,
                                            device.Vehicle.Customer.Name,
                                            device.Vehicle.EngineNo,
                                            device.Vehicle.ChassiNo,
                                            device.Vehicle.VehicleType.Displacement,
                                            device.Vehicle.VehicleType.EngineType,
                                            device.Customer.IdentityNo,
                                            device.Customer.Gender == "女" ? "2" : (device.Customer.Gender == "男"?"1":"0")
                                            );
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.UpdMesByUpdClient(
                                               PID,
                                               Pwd,
                                               device.IDCSimNumber,
                                               device.Vehicle.VehicleType.Model,
                                               device.Vehicle.VehicleLicense,
                                               device.Vehicle.Customer.Name,
                                               device.Vehicle.EngineNo,
                                               device.Vehicle.ChassiNo,
                                               device.Vehicle.VehicleType.Displacement,
                                               device.Vehicle.VehicleType.EngineType);
            }
            return ValideReturnMessageFromZIC(ret);                        
        }
       
        public bool DeviceRegister(Device device, string is5101CallCenter,out DateTime registerDate)
        {
            string ret;
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.ProductRegister(
                                             device.DeviceKey,
                                             device.IDCSimNumber,
                                             PID,
                                             Pwd,
                                             device.Vehicle.VehicleLicense,
                                             device.Customer.Name,
                                             "32",
                                             device.Vehicle.VehicleType.Model,
                                             device.Customer.IdentityNo,
                                             device.DeviceType,
                                             "RDS",
                                             device.Vehicle.EngineNo,
                                             device.Vehicle.ChassiNo,
                                             is5101CallCenter,
                                             device.Vehicle.VehicleType.Displacement,
                                             device.Vehicle.VehicleType.EngineType,
                                             device.Customer.Gender.Equals("男")?1:device.Customer.Gender.Equals("女")?2:0,
                                             device.Vehicle.VehicleType.Manufacture,
                                             device.SimCard);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.ProductRegister(device.DeviceKey,
                                             device.IDCSimNumber,
                                             PID,
                                             Pwd,
                                             device.Vehicle.VehicleLicense,
                                             device.Customer.Name,
                                             "32",
                                             device.Vehicle.VehicleType.Model,
                                             device.Customer.IdentityNo,
                                             device.DeviceType,
                                             "CCF",
                                             device.Vehicle.EngineNo,
                                             device.Vehicle.ChassiNo,
                                             is5101CallCenter,
                                             device.Vehicle.VehicleType.Displacement,
                                             device.Vehicle.VehicleType.EngineType);
            }
            
            //"IDCRegisterDate=2011-05-12 04:32:36"
            LoggerHelper.LogCCF20(string.Format("ProductRegister ZIC's Response:{0}", ret));
            if (ret.Split('=').Count() > 1)
            {
                if (DateTime.TryParse(ret.Split('=')[1],out registerDate))
                {
                    LoggerHelper.LogCCF20(string.Format("Successfully parse the RegisterDate from ZIC {0}", registerDate));
                    return true;
                }else
                {
                    LoggerHelper.LogCCF20(string.Format("Failed to parse the RegisterDate from ZIC {0}", ret));
                    return false;
                }
            }
            else
            {
                registerDate = DateTime.Now;
                return ValideReturnMessageFromZIC(ret);
            }
            

        }
        public bool DeviceUnRegister(Device device)
        {
            string ret;
            if (ZICMonitorModel.IsJava)
            {
                LoggerHelper.LogCCF20(string.Format("cancelproductRegister：IDS={0} Pwd={1},IDCSimNumber={2},DeviceKey={3}",
                                                        PID,
                                                        Pwd,
                                                        device.IDCSimNumber,
                                                        device.DeviceKey));
                
                ret = ZICMonitorModel.ZICJava.cancelproductRegister(
                                                    device.IDCSimNumber,
                                                    PID,
                                                    Pwd,
                                                    device.DeviceKey);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.cancelproductRegister(
                                                    device.IDCSimNumber,
                                                    PID,
                                                    Pwd,
                                                    device.DeviceKey);
            }
            return ValideReturnMessageFromZIC(ret);
            
        }
        public bool SpecialIDCRegister(Device device)
        {
            string ret;
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.SpecialIDcReg(PID, Pwd, device.IDCSimNumber);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.SpecialIDcReg(PID, Pwd, device.IDCSimNumber);
            }

            return ValideReturnMessageFromZIC(ret);
        }
        public bool SpecialIDCUnRegister(Device device)
        {
            string ret;
            LoggerHelper.LogCCF20(string.Format("SpecialIDCUnRegister：IDS={0} Pwd={1},IDCSimNumber={2}", PID, Pwd, device.IDCSimNumber));
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.cancelIDcReg(PID, Pwd, device.IDCSimNumber);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.cancelIDcReg(PID, Pwd, device.IDCSimNumber);
            }
            
            return ValideReturnMessageFromZIC(ret);
        }
        public bool IsSpecialIDC(Device device)
        {
            string ret;
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.IsSpIDC(PID, Pwd, device.IDCSimNumber);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.IsSpIDC(PID, Pwd, device.IDCSimNumber);
            }
            return ValideReturnMessageFromZIC(ret);
            
        }
        public bool ValideReturnMessageFromZIC(string ret)
        {
            StackTrace stackTrace = new StackTrace();
            if (ret == null)
            {
                LoggerHelper.LogCCF20(string.Format("ZIC 调用:{0} 返回为空，请与智信通联系", stackTrace.GetFrame(1).GetMethod().Name));
                return false;
            }
            else
            {
                LoggerHelper.LogCCF20(string.Format("ZIC 调用:{0}返回值为{1}", stackTrace.GetFrame(1).GetMethod().Name,ret));
            }
            switch (ret.ToLower())
            {
                case "exist":
                    return true;
                case "true":
                    return true;
                case "false":
                    return false;
                case "client_error":
                    Utility.ShowMessageBox(Message.ZIC_AlreadyRegistered);
                    return true;
                case "shopid_error":
                    Utility.ShowMessageBox(Message.ZIC_IDSMismatch);
                    return false;
                case "not_sell":
                case "nosell":
                    Utility.ShowMessageBox(Message.ZIC_IDCNotSold);
                    return false;
                case "paraerr":
                case "err":
                    Utility.ShowMessageBox(Message.ZIC_DataError);
                    return false;
                case "idssame":
                    Utility.ShowMessageBox(Message.ZIC_SameIDS);
                    return false;
                case "no_fit":
                case "nofit":
                    Utility.ShowMessageBox(Message.ZIC_NotExistingIDC);
                    return false;
                case "replace_true":
                    Utility.ShowMessageBox(Message.ZIC_ReplaceSucceed);
                    return true;
                case "replace_false":
                    Utility.ShowMessageBox(Message.ZIC_ReplaceFailed);
                    return false;
                case "noexist":
                    Utility.ShowMessageBox(Message.ZIC_IDCNotRegistered);
                    return false;
                case "delfail":
                    Utility.ShowMessageBox(Message.ZIC_DeleteFailed);
                    return false;
                case "sim_use":
                    Utility.ShowMessageBox(Message.ZIC_SIMCardUsed);
                    return false;
                default:
                    Utility.ShowMessageBox(ret);
                    return false;
            }
        }
        public void GetVehicleType()
        {
            CCF20Entities ccf20Ent = new CCF20Entities();
            maintenanceModel = new VehicleMaintenanceModel(ccf20Ent);
            int temp = maintenanceModel.GetMaxVehicleTypeID();
            string ret;
            LoggerHelper.LogCCF20(string.Format("获取ZIC车型：IDS={0} Pwd={1},LastAnchiID={2}", PID, Pwd, temp));
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.GetCarTy(PID, Pwd, temp.ToString());
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.GetCarTy(PID, Pwd, temp.ToString());
            }
            if (ret == null) return;
            List<CarTyModel> list = (List<CarTyModel>)JavaScriptConvert.DeserializeObject(ret, typeof(List<CarTyModel>));

            foreach (CarTyModel model in list)
            {
                //if ((ZICMonitorModel.IsJava && model.brand.Trim() != "FAW-VW") ||
                //    (!ZICMonitorModel.IsJava && model.brand.Trim() == "FAW-VW"))
                //{

                if (model.id != null && model.id > 0)
                {

                    VehicleType vehicleType = new VehicleType();
                    vehicleType.AnchiID = model.id;
                    vehicleType.Model = model.carType.Trim();
                    vehicleType.Manufacture = model.brand.Trim();
                    vehicleType.EngineType = model.Engine_type.Trim();
                    vehicleType.Displacement = model.displacement.Trim();
                    vehicleType.ModelYear = model.CAR_YEAR;
                    maintenanceModel.UpdateVehicleType(vehicleType);
                }
                else
                {
                    LoggerHelper.LogCCF20(string.Format("[ Warning GetVehicleType] AnchiID 为空 厂商={0} 车型={1} 引擎={2}", model.brand, model.carType, model.Engine_type));
                }

            }
            maintenanceModel.Update();
        }
        //在从ZIC 获取的车型和保养项目中，AnchiID 都是从ZIM的车型表和保养表中的记录ID。
        //保养项目中的TYID 对应于车型表中的 ZIM ID （ANCHIID)
        //保养项目中的VehicleTypeID 对应于车型表中的 实际的记录 ID （ANCHIID)
        public void GetMaintenanceType()
        {
            CCF20Entities ccf20Ent = new CCF20Entities();
            maintenanceModel = new VehicleMaintenanceModel(ccf20Ent);
            int temp = maintenanceModel.GetMaxMaintenanceTypeID();
            string ret;
            LoggerHelper.LogCCF20(string.Format("获取ZIC保养项目：IDS={0} Pwd={1},LastAnchiID={2}",PID,Pwd,temp));
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.GetTymaintain(PID, Pwd, temp.ToString());
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.GetTymaintain(PID, Pwd, temp.ToString());
            }
            if (ret == null) return;
            List<TymaintainModel> list = (List<TymaintainModel>)JavaScriptConvert.DeserializeObject(ret, typeof(List<TymaintainModel>));

            foreach (TymaintainModel model in list)
            {

                int tempVehicleType = 0;
                int.TryParse(model.tyid, out tempVehicleType);
                if (model.id > 0 && tempVehicleType > 0)
                {
                    LoggerHelper.LogCCF20(string.Format("TyID:{0}\tAnchiID:{1}\tName:{2}", model.tyid, model.id, model.MaintainPj.Trim()));
                    MaintenanceType maintenanceType = new MaintenanceType();
                    maintenanceType.VehicleTypeID = tempVehicleType;
                    maintenanceType.TyID = model.tyid;
                    maintenanceType.AnchiID = model.id;
                    maintenanceType.ServicePeriod = (model.MaintainPeriod == null ? 0 : Convert.ToInt32(model.MaintainPeriod));
                    maintenanceType.Name = model.MaintainPj.Trim();
                    maintenanceType.ServiceMileage = (model.mileage == null ? 0 : Convert.ToInt32(model.mileage));
                    maintenanceType.Priority = 1;
                    maintenanceModel.UpdateMaintenanceType(maintenanceType);
                    maintenanceModel.Update();
                }
                else
                {
                    LoggerHelper.LogCCF20(string.Format("[Waring GetMaintenanceType]TyID=0 or Model.Id=0 Name:{0}", model.MaintainPj));
                }
            }
            
        }
        public string ClearCode(string idc, string codeType)
        {
            if (ZICMonitorModel.IsJava)
            {
                return ZICMonitorModel.ZICJava.ClearCodes(PID, Pwd, idc, 14, codeType);
            }
            else
            {
                return ZICMonitorModel.ZICSvc.ClearCodes(PID, Pwd, idc, 14, Convert.ToInt16(codeType));
            }
            
        }
        public bool TransferCustomer(TransferedCustomer transfer)
        {
            string ret = string.Empty;
            if (ZICMonitorModel.IsJava)
            {
                ret =ZICMonitorModel.ZICJava.EditDevice(PID,Pwd,transfer.DeviceKey,transfer.IDCNum);
                                                   

            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.EditDevice(PID, Pwd, transfer.DeviceKey, transfer.IDCNum);
            }
            return ValideReturnMessageFromZIC(ret);

        }
        public void ConfirmTransferCustomer()
        {
            string ret = string.Empty;
            DateTime? lastTransfer = deviceModel.GetConfirmTransferDateTime();
            if (lastTransfer == null)
            {
                lastTransfer = DateTime.Now- new TimeSpan(0,1,0,0);
            }
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.GetZYList(PID, Pwd, (DateTime)lastTransfer);
            }
            else
            {
                ret = ZICMonitorModel.ZICSvc.GetZYList(PID, Pwd, (DateTime)lastTransfer);
            }
            
            if (ret == null || ret == string.Empty)
            {
                return;
            }
            List<ConFirmDeviceModel> list = (List<ConFirmDeviceModel>)JavaScriptConvert.DeserializeObject(ret, typeof(List<ConFirmDeviceModel>));
            foreach (ConFirmDeviceModel device in list)
            {
                string deviceKey = deviceModel.GetDeviceKeyBySimNumber(device.DeviceId);
                int customerID = deviceModel.GetCustomerIDByTransferSimNumber(device.DeviceId);
                int vehicleID = deviceModel.GetVehicleIDByTransferSimNumber(device.DeviceId);
                if ( deviceKey == string.Empty || customerID ==0 ) continue;

                Device confirmedDevice = new Device();
                confirmedDevice.CustomerID = customerID;
                DateTime registerDate;
                if (DateTime.TryParse(device.OutDate, out registerDate))
                {
                    confirmedDevice.RegisterDate = registerDate;
                }else
                {
                    LoggerHelper.LogCCF20(string.Format("确认转移设备 不正确的注册日期={0}",device.OutDate));
                }
                confirmedDevice.DeviceType = device.deviceType;
                confirmedDevice.IDCSimNumber = device.DeviceId;
                confirmedDevice.TerminalType = device.terminalType;
                confirmedDevice.IsRegistered = true;
                confirmedDevice.IsActive = true;
                confirmedDevice.DeviceKey = deviceKey;
                confirmedDevice.IsTransfer = true;
                confirmedDevice.DeviceStatus = DeviceStatus.Sold;
                confirmedDevice.CustomerID = customerID;
                confirmedDevice.VehicleID = vehicleID;
                deviceModel.AddDevice(confirmedDevice);
                Utility.ShowMessageBox(string.Format(Message.ZIC_IDSTransferSucceed, confirmedDevice.IDCSimNumber));
                deviceModel.UpdateConfirmTransferDateTime();
            }
            
            LoggerHelper.LogCCF20(string.Format("GetZYList IDS={0},Count={1}", PID, list.Count));
            

        }
        public string UpdateCompanyProfile(string LoginName,
                                            string CompanyName,
                                            string ExcuteMan,
                                            string LinkPhone,
                                            string CompanyPhone,
                                            string CompanyFax,
                                            string CompanyWebSite,
                                            string CompanyAddress)
        {
            string ret = string.Empty;
            if (ZICMonitorModel.IsJava)
            {
                ZICMonitorModel.ZICJava.UpdateCustomInfo(PID,
                                              Pwd,
                                              LoginName,
                                              CompanyName,
                                              ExcuteMan,
                                              LinkPhone,
                                              CompanyPhone,
                                              CompanyFax,
                                              CompanyWebSite,
                                              CompanyAddress);
            }
            else
            {
                ZICMonitorModel.ZICSvc.UpdateCustomInfo(PID,
                                              Pwd,
                                              LoginName,
                                              CompanyName,
                                              ExcuteMan,
                                              LinkPhone,
                                              CompanyPhone,
                                              CompanyFax,
                                              CompanyWebSite,
                                              CompanyAddress);
            }
            
            if (ret == null) return "";
            switch (ret.ToLower())
            {
                case "true": 
                    ret = "更新成功";
                    break;
                case "false":
                    ret = "更新失败";
                    break;
                case "loginerr":
                    ret = "登录失败";
                    break;
                case "err":
                    ret = "数据有误";
                    break;
            }
            return ret;
        }
        public bool ReturnProdcut(string previousIDC,string previousDeviceKey,string newIDC,string newDeviceKey)
        {
            string ret;
            LoggerHelper.LogCCF20(string.Format("ProductReturn：IDS={0} Pwd={1},PreviousIDC={2},previousDeviceKey={3},newIDC={4},newDeviceKey={5}", 
                                                    PID,
                                                    Pwd,
                                                    previousIDC,
                                                    previousDeviceKey,
                                                    newIDC,
                                                    newDeviceKey));
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.ProductReturn(
                                                PID,
                                                Pwd,
                                                previousDeviceKey,
                                                previousIDC,
                                                newDeviceKey,
                                                newIDC
                                                );
                return ValideReturnMessageFromZIC(ret);
            }
            else
            {
                throw new NotImplementedException();
         
            }
            
        }
        public void GetClearCodeResult()
        {
            string ret;

            if (ZICMonitorModel.IsJava)
            {
                LoggerHelper.LogCCF20(string.Format("GetClearCodeResult: PID={0},Pwd={1},AnChiID={2}",
                                                        PID,
                                                        Pwd,
                                                        vehicleModel.GetMaxClearCodeResultId()));
                ret = ZICMonitorModel.ZICJava.GetClearcoderesult(PID,Pwd,vehicleModel.GetMaxClearCodeResultId());
                if (ret == null) return;
                List<ClearcodeResultData> list = (List<ClearcodeResultData>)JavaScriptConvert.DeserializeObject(ret, typeof(List<ClearcodeResultData>));
                foreach (ClearcodeResultData clearCodeResult in list)
                {
                    ClearCodeHistory clearCodeHistory = new ClearCodeHistory();
                    int tempId;
                    clearCodeHistory.AnchiID = int.TryParse(clearCodeResult.id, out tempId) ? tempId : 0;
                    clearCodeHistory.ErrMsg = clearCodeResult.errMessage;
                    clearCodeHistory.IDCSimNumber = clearCodeResult.idc.Trim();
                    switch (clearCodeResult.sendStatu.Trim())
                    {
                        case "0":
                            clearCodeHistory.SendStatus = "未发送";
                            break;
                        case "1":
                            clearCodeHistory.SendStatus = "发送成功";
                            break;
                        case "2":
                            clearCodeHistory.SendStatus = "发送失败";
                            break;
                        case "9":
                            clearCodeHistory.SendStatus = "准备发送";
                            break;
                        case "90":
                            clearCodeHistory.SendStatus = "等待返馈";
                            break;
                        default:
                            clearCodeHistory.SendStatus = string.Format("未知代码:{0}",clearCodeResult.sendStatu);
                            break;
                    }
                    
                    DateTime tempDate;
                    clearCodeHistory.SendTime = DateTime.TryParse(clearCodeResult.sendTime, out tempDate) ? tempDate : DateTime.Now;
                    vehicleModel.AddClearCodeResult(clearCodeHistory);
                }
                

            }
            else
            {
                throw new NotImplementedException();

            }
        }
        public bool AddSalesList(string deviceKey, out string deviceType, out string simCard,out string idc)
        {
            string ret;
            deviceType = string.Empty;
            simCard = string.Empty;
            idc = string.Empty;

            LoggerHelper.LogCCF20(string.Format("AddSalesList：IDS={0} Pwd={1},deviceKey={2}",
                                                    PID,
                                                    Pwd,
                                                    deviceKey
                                                    ));
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.AddSalesList(
                                                PID,
                                                Pwd,
                                                string.Empty,//deviceType,
                                                deviceKey,
                                                string.Empty//idcSimNumber
                                                );
                if (ret.ToLower() != "false")
                {
                    var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    
                    SAXlHModel myData;
                    try
                    {
                        myData = jsonSerializer.Deserialize<SAXlHModel>(ret);
                    }
                    catch
                    {
                        LoggerHelper.LogCCF20(string.Format("[AddSalesList Return Fail]：{0}", ret));
                        return ValideReturnMessageFromZIC(ret);
                    }
                    deviceType = myData.productmodel;
                    simCard = myData.simnum;
                    idc = myData.idc;
                    LoggerHelper.LogCCF20(string.Format("[AddSalesList Return Success]：IDC={0} Sim={1},SerialNo={2},deviceType={3}",
                                                      idc,
                                                      simCard,
                                                      deviceKey,
                                                      deviceType
                                                      ));
                    return true;
                }
                else
                {
                    LoggerHelper.LogCCF20(string.Format("[AddSalesList Return Fail]：{0}", ret));
                    return ValideReturnMessageFromZIC(ret);
                }
            }
            else
            {
                throw new NotImplementedException();

            }

        }
        public bool RemoveSaleList(string deviceKey, string idc)
        {
            string ret;
            LoggerHelper.LogCCF20(string.Format("DeleteSaleList：IDS={0} Pwd={1},deviceKey={2},idcSimNumber={3}",
                                                    PID,
                                                    Pwd,
                                                    deviceKey,
                                                    idc));
            if (ZICMonitorModel.IsJava)
            {
                ret = ZICMonitorModel.ZICJava.DeleteSa(
                                                PID,
                                                Pwd,
                                                deviceKey,
                                                idc);
                return ValideReturnMessageFromZIC(ret);
            }
            else
            {
                throw new NotImplementedException();

            }
        }
        public bool AddPreOrder(string customerID)
        {
            LoggerHelper.LogCCF20(string.Format("YuDingInfo：IDS={0} Pwd={1},customerID={2}",
                                                  PID,
                                                  Pwd,
                                                  customerID));

            if (ZICMonitorModel.IsJava)
            {
                string ret = ZICMonitorModel.ZICJava.YuDingInfo(PID, Pwd, customerID);
                return ValideReturnMessageFromZIC(ret);
            }
            else
            {
                return false;
            }
        }
        public void RemovePreOrder(string customerID)
        {
            LoggerHelper.LogCCF20(string.Format("RemoteYuDingInfo：IDS={0} Pwd={1},customerID={2}",
                                                  PID,
                                                  Pwd,
                                                  customerID));

            if (ZICMonitorModel.IsJava)
            {
                string ret = ZICMonitorModel.ZICJava.RemoteYuDingInfo(PID, Pwd, customerID);
                ValideReturnMessageFromZIC(ret);
            }
        }
        static public bool CheckLogin(string ids, string passswrod)
        {
            LoggerHelper.LogCCF20(string.Format("CheckLogin IDS={0} Pwd={1} Url={2}", ids,passswrod,ZICMonitorModel.ZICJava.Url));
            return  ZICMonitorModel.ZICJava.Checklogin(ids, passswrod).ToLower() == "true"? true:false;
        }
    }
}
